import React, { Component } from 'react';
import { Form, Row, Col } from 'antd';
import ShowType from '../../../routes/common/showType';
import styles from '../../../index.less';

const FormItem = Form.Item;

class TabFinanceOfferComponent extends Component {
  constructor(props) {
    super(props);
    this.state = {
      sTabId: props.app.currentPane.key, /* 当前标签 */
      componentName: props.componentName, /* 组件名 */
      masterConfig: props.masterConfig, /* 配置 */
      sId: props.sId, /* 业务数据Id */
      dataList: [], /* 数据 */
      sActiveId: props.sActiveId, /* 窗体Id */
      disabled: props.disabled, /* 是否是查看状态 */
      tabFinanceControl: '', /* 财务控制 */
      tabOffer: '', /* 报价功能设定 */
      tabInventoryControl: '', /* 库存控制 */
      sCbxPayablesType: '', /* 应付款源单类型 */
      sCbxOutSidePayType: '', /* 发外应付源类型 */
      sCbxReceivablesType: '', /* 应收款源单类型 */
      // iNetCompanyAccountDate: '', /* 公司对账日期 */
      sCbxGetPayStandard: '', /* 结算日期标准 */
      sCbxBusinessType: '', /* 主要业务类型 */
      sCbxAdvanceType: '', /* 订单收取对象 */
      sCbxMaterialsCostMode: '', /* 成本计算方式 */
      iNetMoneyInaccuracies: '', /* 金额误差值 */
      bCkxARExceed: '', /* 应收款超出使用额度 */
      bCkxWebNotInFinance: '', /* 网络用户不进财务管理 */
      bCkxStrictPlanPrchasePrice: '', /* 严格按计划采购价 */
      bCkxMaterialsTax: '', /* 材料成本价含税 */
      iNetIntervalDays: '', /* 间隔天数 */
      sCbxOfferMaterials: '', /* 报价时材料费在 */
      iNetVeryHighPercentage: '', /* 基础上上调(%) */
      sCbxProcessPrice: '', /* 工序价格设定方式 */
      bCkxOfferFunctionality: '', /* 启用重新报价功能 */
      bCkxNoTaxProcessPrice: '', /* 启用工序价格不含税 */
      sCbxMaterialsDefine: '', /* 材料自定义取值 */
      sCbxProductDefine: '', /* 成品自定义取值 */
      sCbxSemigoodsDefine: '', /* 半成品自定义取值 */
      sCbxCorrugateWidth: '', /* 瓦楞门幅根据印张 */
      iNetCorrugateWidthSubtract: '', /* 减 */
      sCbxCorrugateLength: '', /* 瓦楞长根据印张 */
      iNetCorrugateLengthSubtract: '', /* 长减 */
      bCkxSemigoodsStockLimit: '', /* 半成品库存不足限制领料 */
      bCkxMaterialsStockPostLimit: '', /* 材料出库保存时校验库存 */
      bCkxMaterialsStockLimit: '', /* 材料库存不足时限制领料 */
      bCkxProductStockLimit: '', /* 成品库存不足时限制送货 */
      bCkxNotStockDeletingMaterial: '', /* 不考虑库存,直接删除物料 */
      bCkxWharehouseLimit: '', /* 启用仓库控制 */
      bCkxBuSampleNoDeliver: '', /* 以工单送货时补单与打样不送货 */
      bCkxReelPaper: '', /* 打勾后不按单领用卷筒纸 */
    };
  }

  componentWillMount() {
    /* 获取主表数据 */
    const { masterConfig, sId } = this.state;
    if (masterConfig.gdsconfigformslave !== undefined) {
      const mainConfig = masterConfig.gdsconfigformslave;
      this.setState({
        sId: sId !== undefined ? sId : '',
        tabFinanceControl: mainConfig.filter(item => (item.sControlName.toLowerCase() === 'tabfinancecontrol'))[0],
        tabOffer: mainConfig.filter(item => (item.sControlName.toLowerCase() === 'taboffer'))[0],
        tabInventoryControl: mainConfig.filter(item => (item.sControlName.toLowerCase() === 'tabinventorycontrol'))[0],
        sCbxPayablesType: mainConfig.filter(item => (item.sControlName.toLowerCase() === 'scbxpayablestype'))[0],
        sCbxOutSidePayType: mainConfig.filter(item => (item.sControlName.toLowerCase() === 'scbxoutsidepaytype'))[0],
        sCbxReceivablesType: mainConfig.filter(item => (item.sControlName.toLowerCase() === 'scbxreceivablestype'))[0],
        // iNetCompanyAccountDate: mainConfig.filter(item => (item.sControlName.toLowerCase() === 'inetcompanyaccountdate'))[0],
        sCbxGetPayStandard: mainConfig.filter(item => (item.sControlName.toLowerCase() === 'scbxgetpaystandard'))[0],
        sCbxBusinessType: mainConfig.filter(item => (item.sControlName.toLowerCase() === 'scbxbusinesstype'))[0],
        sCbxAdvanceType: mainConfig.filter(item => (item.sControlName.toLowerCase() === 'scbxadvancetype'))[0],
        sCbxMaterialsCostMode: mainConfig.filter(item => (item.sControlName.toLowerCase() === 'scbxmaterialscostmode'))[0],
        iNetMoneyInaccuracies: mainConfig.filter(item => (item.sControlName.toLowerCase() === 'inetmoneyinaccuracies'))[0],
        bCkxARExceed: mainConfig.filter(item => (item.sControlName.toLowerCase() === 'bckxarexceed'))[0],
        bCkxWebNotInFinance: mainConfig.filter(item => (item.sControlName.toLowerCase() === 'bckxwebnotinfinance'))[0],
        bCkxStrictPlanPrchasePrice: mainConfig.filter(item => (item.sControlName.toLowerCase() === 'bckxstrictplanprchaseprice'))[0],
        bCkxMaterialsTax: mainConfig.filter(item => (item.sControlName.toLowerCase() === 'bckxmaterialstax'))[0],
        iNetIntervalDays: mainConfig.filter(item => (item.sControlName.toLowerCase() === 'inetintervaldays'))[0],
        sCbxOfferMaterials: mainConfig.filter(item => (item.sControlName.toLowerCase() === 'scbxoffermaterials'))[0],
        iNetVeryHighPercentage: mainConfig.filter(item => (item.sControlName.toLowerCase() === 'inetveryhighpercentage'))[0],
        sCbxProcessPrice: mainConfig.filter(item => (item.sControlName.toLowerCase() === 'scbxprocessprice'))[0],
        bCkxOfferFunctionality: mainConfig.filter(item => (item.sControlName.toLowerCase() === 'bckxofferfunctionality'))[0],
        bCkxNoTaxProcessPrice: mainConfig.filter(item => (item.sControlName.toLowerCase() === 'bckxnotaxprocessprice'))[0],
        sCbxMaterialsDefine: mainConfig.filter(item => (item.sControlName.toLowerCase() === 'scbxmaterialsdefine'))[0],
        sCbxProductDefine: mainConfig.filter(item => (item.sControlName.toLowerCase() === 'scbxproductdefine'))[0],
        sCbxSemigoodsDefine: mainConfig.filter(item => (item.sControlName.toLowerCase() === 'scbxsemigoodsdefine'))[0],
        sCbxCorrugateWidth: mainConfig.filter(item => (item.sControlName.toLowerCase() === 'scbxcorrugatewidth'))[0],
        iNetCorrugateWidthSubtract: mainConfig.filter(item => (item.sControlName.toLowerCase() === 'inetcorrugatewidthsubtract'))[0],
        sCbxCorrugateLength: mainConfig.filter(item => (item.sControlName.toLowerCase() === 'scbxcorrugatelength'))[0],
        iNetCorrugateLengthSubtract: mainConfig.filter(item => (item.sControlName.toLowerCase() === 'inetcorrugatelengthsubtract'))[0],
        bCkxSemigoodsStockLimit: mainConfig.filter(item => (item.sControlName.toLowerCase() === 'bckxsemigoodsstocklimit'))[0],
        bCkxMaterialsStockPostLimit: mainConfig.filter(item => (item.sControlName.toLowerCase() === 'bckxmaterialsstockpostlimit'))[0],
        bCkxMaterialsStockLimit: mainConfig.filter(item => (item.sControlName.toLowerCase() === 'bckxmaterialsstocklimit'))[0],
        bCkxProductStockLimit: mainConfig.filter(item => (item.sControlName.toLowerCase() === 'bckxproductstocklimit'))[0],
        bCkxNotStockDeletingMaterial: mainConfig.filter(item => (item.sControlName.toLowerCase() === 'bckxnotstockdeletingmaterial'))[0],
        bCkxWharehouseLimit: mainConfig.filter(item => (item.sControlName.toLowerCase() === 'bckxwharehouselimit'))[0],
        bCkxBuSampleNoDeliver: mainConfig.filter(item => (item.sControlName.toLowerCase() === 'bckxbusamplenodeliver'))[0],
        bCkxReelPaper: mainConfig.filter(item => (item.sControlName.toLowerCase() === 'bckxreelpaper'))[0],
      });
    }
  }

  componentWillReceiveProps(nextProps) {
    const {
      sId, disabled, content, dataSet,
    } = nextProps;
    const { dataList } = content;
    const {
      sDataListTabId, returnType, urlData, loading, componentName,
    } = dataList;
    this.setState({ disabled, dataList: dataSet });
    if (this.state.sTabId === sDataListTabId && this.state.sTabId === nextProps.app.currentPane.key
      && this.state.componentName === componentName) {
      if (loading) return;
      if (returnType === 'data') {
        this.setState({
          dataList: urlData,
          sId: sId !== undefined ? sId : '',
        });
      }
    }
  }

  shouldComponentUpdate(nextProps, nextState) {
    const { componentName } = nextProps;
    const { sId } = this.props;
    if (sId === undefined) {
      return true;
    }
    let flag = true;
    if (nextState.disabled !== this.state.disabled) {
      return true;
    }
    if (this.state.sTabId === nextProps.app.currentPane.key &&
      this.state.componentName === componentName) {
      flag = true;
    } else {
      flag = false;
    }
    return flag;
  }

  render() {
    const {
      app, form, handleModalPane, dataName, dataType, handleSelectChange, onClose,
    } = this.props;
    const {
      dataList, sId, sActiveId, disabled,
    } = this.state;
    const childProps = {
      app,
      form,
      sActiveId,
      dataList,
      sId,
      disabled,
      handleModalPane,
      handleSelectChange,
      dataName,
      dataType,
      onClose,
    };
    const formItemLayout = { labelCol: { span: 12 }, wrapperCol: { span: 12 } };
    const { tabFinanceControl, tabOffer, tabInventoryControl } = this.state;
    const {
      sCbxPayablesType, sCbxOutSidePayType, sCbxReceivablesType, /* iNetCompanyAccountDate, */ sCbxGetPayStandard, sCbxBusinessType, sCbxAdvanceType,
    } = this.state;
    const {
      sCbxMaterialsCostMode, iNetMoneyInaccuracies, bCkxARExceed, bCkxWebNotInFinance, bCkxStrictPlanPrchasePrice,
    } = this.state;
    const { bCkxMaterialsTax, iNetIntervalDays } = this.state;
    const { sCbxOfferMaterials, iNetVeryHighPercentage, sCbxProcessPrice } = this.state;
    const { bCkxOfferFunctionality, bCkxNoTaxProcessPrice, sCbxSemigoodsDefine } = this.state;
    const {
      sCbxMaterialsDefine, sCbxProductDefine, sCbxCorrugateWidth, iNetCorrugateWidthSubtract, sCbxCorrugateLength, iNetCorrugateLengthSubtract,
    } = this.state;
    const {
      bCkxSemigoodsStockLimit, bCkxMaterialsStockPostLimit, bCkxMaterialsStockLimit, bCkxProductStockLimit,
    } = this.state;
    const {
      bCkxNotStockDeletingMaterial, bCkxWharehouseLimit, bCkxBuSampleNoDeliver, bCkxReelPaper,
    } = this.state;
    const sCbxPayablesTypeProps = { showConfig: sCbxPayablesType, ...childProps };
    const sCbxOutSidePayTypeProps = { showConfig: sCbxOutSidePayType, ...childProps };
    const sCbxReceivablesTypeProps = { showConfig: sCbxReceivablesType, ...childProps };
    // const iNetCompanyAccountDateProps = { showConfig: iNetCompanyAccountDate, ...childProps };
    const sCbxGetPayStandardProps = { showConfig: sCbxGetPayStandard, ...childProps };
    const sCbxBusinessTypeProps = { showConfig: sCbxBusinessType, ...childProps };
    const sCbxAdvanceTypeProps = { showConfig: sCbxAdvanceType, ...childProps };
    const sCbxMaterialsCostModeProps = { showConfig: sCbxMaterialsCostMode, ...childProps };
    const iNetMoneyInaccuraciesProps = { showConfig: iNetMoneyInaccuracies, ...childProps };
    const bCkxARExceedProps = { showConfig: bCkxARExceed, ...childProps };
    const bCkxWebNotInFinanceProps = { showConfig: bCkxWebNotInFinance, ...childProps };
    const bCkxStrictPlanPrchasePriceProps = { showConfig: bCkxStrictPlanPrchasePrice, ...childProps };
    const bCkxMaterialsTaxProps = { showConfig: bCkxMaterialsTax, ...childProps };
    const iNetIntervalDaysProps = { showConfig: iNetIntervalDays, ...childProps };
    const sCbxOfferMaterialsProps = { showConfig: sCbxOfferMaterials, ...childProps };
    const iNetVeryHighPercentageProps = { showConfig: iNetVeryHighPercentage, ...childProps };
    const sCbxProcessPriceProps = { showConfig: sCbxProcessPrice, ...childProps };
    const bCkxOfferFunctionalityProps = { showConfig: bCkxOfferFunctionality, ...childProps };
    const bCkxNoTaxProcessPriceProps = { showConfig: bCkxNoTaxProcessPrice, ...childProps };
    const sCbxMaterialsDefineProps = { showConfig: sCbxMaterialsDefine, ...childProps };
    const sCbxProductDefineProps = { showConfig: sCbxProductDefine, ...childProps };
    const sCbxSemigoodsDefineProps = { showConfig: sCbxSemigoodsDefine, ...childProps };
    const sCbxCorrugateWidthProps = { showConfig: sCbxCorrugateWidth, ...childProps };
    const iNetCorrugateWidthSubtractProps = { showConfig: iNetCorrugateWidthSubtract, ...childProps };
    const sCbxCorrugateLengthProps = { showConfig: sCbxCorrugateLength, ...childProps };
    const iNetCorrugateLengthSubtractProps = { showConfig: iNetCorrugateLengthSubtract, ...childProps };
    const bCkxSemigoodsStockLimitProps = { showConfig: bCkxSemigoodsStockLimit, ...childProps };
    const bCkxMaterialsStockPostLimitProps = { showConfig: bCkxMaterialsStockPostLimit, ...childProps };
    const bCkxMaterialsStockLimitProps = { showConfig: bCkxMaterialsStockLimit, ...childProps };
    const bCkxProductStockLimitProps = { showConfig: bCkxProductStockLimit, ...childProps };
    const bCkxNotStockDeletingMaterialProps = { showConfig: bCkxNotStockDeletingMaterial, ...childProps };
    const bCkxWharehouseLimitProps = { showConfig: bCkxWharehouseLimit, ...childProps };
    const bCkxBuSampleNoDeliverProps = { showConfig: bCkxBuSampleNoDeliver, ...childProps };
    const bCkxReelPaperProps = { showConfig: bCkxReelPaper, ...childProps };
    return (
      <FormItem className={styles.searchSlaveForm}>
        <Row type="flex" justify="space-between">
          <Col span={11}>
            <div className={styles.tabChild}>
              <div className={styles.tabChildTitle}>
                <span>{tabFinanceControl.showName}</span>
              </div>
              <Row type="flex" justify="space-between">
                <Col span={11}>
                  <ShowType sName="sCbxPayablesType" useParentName showDefaultName="应付款源单类型" {...sCbxPayablesTypeProps} formItemLayout={formItemLayout} />
                  <ShowType sName="sCbxOutSidePayType" useParentName showDefaultName="发外应付源类型" {...sCbxOutSidePayTypeProps} formItemLayout={formItemLayout} />
                  <ShowType sName="sCbxReceivablesType" useParentName showDefaultName="应收款源单类型" {...sCbxReceivablesTypeProps} formItemLayout={formItemLayout} />
                  <ShowType sName="sCbxBusinessType" useParentName showDefaultName="主要业务类型" {...sCbxBusinessTypeProps} formItemLayout={formItemLayout} />
                  <ShowType sName="sCbxAdvanceType" useParentName showDefaultName="订单收取对象" {...sCbxAdvanceTypeProps} formItemLayout={formItemLayout} />
                </Col>
                <Col span={11}>
                  {/* <ShowType sName="iNetCompanyAccountDate" useParentName showDefaultName="公司对账日期" {...iNetCompanyAccountDateProps} formItemLayout={formItemLayout} /> */}
                  <ShowType sName="sCbxGetPayStandard" useParentName showDefaultName="结算日期标准" {...sCbxGetPayStandardProps} formItemLayout={formItemLayout} />
                  <ShowType sName="sCbxMaterialsCostMode" useParentName showDefaultName="成本计算方式" {...sCbxMaterialsCostModeProps} formItemLayout={formItemLayout} />
                  <ShowType sName="iNetMoneyInaccuracies" useParentName showDefaultName="金额误差值" {...iNetMoneyInaccuraciesProps} formItemLayout={formItemLayout} />
                </Col>
              </Row>
              <Row type="flex" justify="space-between">
                <Col span={11}>
                  <ShowType sName="bCkxStrictPlanPrchasePrice" useParentName showDefaultName="严格按计划采购价" {...bCkxStrictPlanPrchasePriceProps} formItemLayout={formItemLayout} />
                  <ShowType sName="bCkxMaterialsTax" useParentName showDefaultName="材料成本价含税" {...bCkxMaterialsTaxProps} formItemLayout={formItemLayout} />
                </Col>
                <Col span={11}>
                  <ShowType sName="bCkxARExceed" useParentName showDefaultName="应收款超出使用额度" {...bCkxARExceedProps} formItemLayout={formItemLayout} />
                  <ShowType sName="bCkxWebNotInFinance" useParentName showDefaultName="网络用户不进财务管理" {...bCkxWebNotInFinanceProps} formItemLayout={formItemLayout} />
                </Col>
              </Row>
            </div>
          </Col>
          <Col span={11}>
            <div className={styles.tabChild}>
              <div className={styles.tabChildTitle}>
                <span>{tabOffer.showName}</span>
              </div>
              <Row type="flex" justify="space-between">
                <Col span={11}>
                  <ShowType sName="iNetIntervalDays" useParentName showDefaultName="间隔天数" {...iNetIntervalDaysProps} formItemLayout={formItemLayout} />
                  <ShowType sName="sCbxOfferMaterials" useParentName showDefaultName="报价时材料费在" {...sCbxOfferMaterialsProps} formItemLayout={formItemLayout} />
                </Col>
                <Col span={11}>
                  <ShowType sName="sCbxProcessPrice" useParentName showDefaultName="工序价格设定方式" {...sCbxProcessPriceProps} formItemLayout={formItemLayout} />
                  <ShowType sName="iNetVeryHighPercentage" useParentName showDefaultName="基础上上调(%)" {...iNetVeryHighPercentageProps} formItemLayout={formItemLayout} />
                </Col>
              </Row>
              <Row type="flex" justify="space-between">
                <Col span={11}>
                  <ShowType sName="bCkxOfferFunctionality" useParentName showDefaultName="启用重新报价功能" {...bCkxOfferFunctionalityProps} formItemLayout={formItemLayout} />
                </Col>
                <Col span={11}>
                  <ShowType sName="bCkxNoTaxProcessPrice" useParentName showDefaultName="启用工序价格不含税" {...bCkxNoTaxProcessPriceProps} formItemLayout={formItemLayout} />
                </Col>
              </Row>
            </div>
          </Col>
          <Col span={24}>
            <div className={styles.tabChild}>
              <div className={styles.tabChildTitle}>
                <span>{tabInventoryControl.showName}</span>
              </div>
              <Row type="flex" justify="space-between">
                <Col span={11}>
                  <Row type="flex" justify="space-between">
                    <Col span={11}>
                      <ShowType sName="sCbxMaterialsDefine" useParentName showDefaultName="材料自定义取值" {...sCbxMaterialsDefineProps} formItemLayout={formItemLayout} />
                      <ShowType sName="sCbxSemigoodsDefine" useParentName showDefaultName="半成品自定义取值" {...sCbxSemigoodsDefineProps} formItemLayout={formItemLayout} />
                    </Col>
                    <Col span={11}>
                      <ShowType sName="sCbxProductDefine" useParentName showDefaultName="成品自定义取值" {...sCbxProductDefineProps} formItemLayout={formItemLayout} />
                    </Col>
                  </Row>
                  <Row type="flex" justify="space-between">
                    <Col span={11}>
                      <ShowType sName="sCbxCorrugateWidth" useParentName showDefaultName="瓦楞门幅根据印张" {...sCbxCorrugateWidthProps} formItemLayout={formItemLayout} />
                      <ShowType sName="sCbxCorrugateLength" useParentName showDefaultName="瓦楞长根据印张" {...sCbxCorrugateLengthProps} formItemLayout={formItemLayout} />
                    </Col>
                    <Col span={11}>
                      <ShowType sName="iNetCorrugateWidthSubtract" useParentName showDefaultName="减" {...iNetCorrugateWidthSubtractProps} formItemLayout={formItemLayout} />
                      <ShowType sName="iNetCorrugateLengthSubtract" useParentName showDefaultName="减" {...iNetCorrugateLengthSubtractProps} formItemLayout={formItemLayout} />
                    </Col>
                  </Row>
                </Col>
                <Col span={11}>
                  <Row type="flex" justify="space-between">
                    <Col span={11}>
                      <ShowType sName="bCkxSemigoodsStockLimit" useParentName showDefaultName="半成品库存不足限制领料" {...bCkxSemigoodsStockLimitProps} formItemLayout={formItemLayout} />
                      <ShowType sName="bCkxMaterialsStockLimit" useParentName showDefaultName="材料库存不足时限制领料" {...bCkxMaterialsStockLimitProps} formItemLayout={formItemLayout} />
                      <ShowType sName="bCkxProductStockLimit" useParentName showDefaultName="成品库存不足时限制送货" {...bCkxProductStockLimitProps} formItemLayout={formItemLayout} />
                      <ShowType sName="bCkxNotStockDeletingMaterial" useParentName showDefaultName="不考虑库存,直接删除物料" {...bCkxNotStockDeletingMaterialProps} formItemLayout={formItemLayout} />
                    </Col>
                    <Col span={11}>
                      <ShowType sName="bCkxMaterialsStockPostLimit" useParentName showDefaultName="材料出库保存时校验库存" {...bCkxMaterialsStockPostLimitProps} formItemLayout={formItemLayout} />
                      <ShowType sName="bCkxWharehouseLimit" useParentName showDefaultName="启用仓库控制" {...bCkxWharehouseLimitProps} formItemLayout={formItemLayout} />
                      <ShowType sName="bCkxBuSampleNoDeliver" useParentName showDefaultName="以工单送货时补单与打样不送货" {...bCkxBuSampleNoDeliverProps} formItemLayout={formItemLayout} />
                      <ShowType sName="bCkxReelPaper" useParentName showDefaultName="打勾后不按单领用卷筒纸" {...bCkxReelPaperProps} formItemLayout={formItemLayout} />
                    </Col>
                  </Row>
                </Col>
              </Row>
            </div>
          </Col>
        </Row>
      </FormItem>
    );
  }
}

export default TabFinanceOfferComponent;
